import { defineStore } from 'pinia'

export const useTabsStore = defineStore('useTabsStore', {
    state: () => {
        return {
            editableTabsValue: '/home',
            editableTabs: [
                {
                    title: '首页',
                    name: '/home'
                }
            ]
        }
    },
    // 也可以这样定义
    // state: () => ({ count: 0 })
    actions: {
        addTabs(tab) {
            if (this.editableTabs.findIndex(e => e.name == tab.path) == -1) {
                this.editableTabs.push({
                    title: tab.menuName,
                    name: tab.path
                })
            }
            this.editableTabsValue = tab.path
        },
        resetTabs() {
            this.editableTabsValue = '/home';
            this.editableTabs = [
                {
                    title: '首页',
                    name: '/home'
                }
            ]
        },
        setEditableTabsValue(val) {
            this.editableTabsValue = val
        },

        setEditableTabs(val) {
            this.editableTabs = val
        },
    },
    persist: {
        enabled: true,
    }
})